package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.union.Parergon;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.CrossUnionParergonMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_UNION_PARERGON_PRE_BUY_PRODUCT, desc = "预购买")
public class CrossPreBuyCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        Parergon.BargainReqMsg reqMsg = Parergon.BargainReqMsg.parseFrom(packet.getBytes());
        int bussinessId = reqMsg.getBussinessId();

        ret = CrossUnionParergonMgr.preBuy(serverId, packet.getPlayerId(), bussinessId);

        if(ret != 0){
            Parergon.BuyProductRespMsg.Builder respMsg = Parergon.BuyProductRespMsg.newBuilder();
            respMsg.setRet(ret);
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_UNION_PARERGON_BUY_PRODUCT, respMsg));
        }
    }

    @Override
    public void sendData() {

    }
}
